# -*- coding:utf-8 -*-
# @FileName :params.py
# @Date: 2024/8/1
# @Author:天空之城
# params/request_params.py
from flask import request
from flask.views import MethodView


class RequestBase(MethodView):
    def __init__(self):
        super().__init__()
        self.request = request

    def get_param(self, param_name):
        # 首先尝试从 JSON 中获取参数
        param_value = self.request.get_json().get(param_name) if self.request.is_json else None

        # 如果 JSON 中没有，则从查询参数中获取
        if param_value is None:
            param_value = self.request.args.get(param_name)

        return param_value
